package com.sanniu.common;

import com.jfinal.aop.Before;
import com.jfinal.core.NotAction;
import com.sanniu.interceptor.PermissionInterceptor;
import com.sanniu.interceptor.UserInterceptor;
import com.sanniu.model.User;
import io.jboot.web.controller.JbootController;

@Before({
        PermissionInterceptor.class,
        UserInterceptor.class
})
public abstract class ControllerBase extends JbootController {
    @NotAction
    public Long getIdPara() {
        Long id = getParaToLong();
        if (id == null) {

            //renderError 会直接抛出异常，阻止程序往下执行
            renderError(404);
        }

        return id;
    }

    @Override
    @NotAction
    public String getPara(String name) {
        String value = super.getPara(name);
        return "".equals(value) ? null : value;
    }

    public User getLoginedUser() {
        return getAttr("userInfo");
    }
}
